/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package service.impl;

import java.util.List;
import pojo.Item;
import service.IItemService;
/**
 *
 * @author administrator
 */
public class ItemServiceImpl <T extends Item> extends ServiceImpl<T>
                 implements IItemService<T>{
    public List<T> listItem(int offset, int pageSize){
        return this.getDao().list("select i from Item i order by i.itemId desc",offset,pageSize,null);
    }

    public int count(){
        return this.getTotalCount("select count(i) from Item i ", null);
    }

    public T getItem(int itemID)
    {
        List<T> item = this.getDao().createQuery(
                " select i from Item i "
                + " where i.itemId = :id ").setParameter("id", itemID).list();

        if (item.size() > 0) {
            return item.get(0);
        }

        return null;
    }

    public void updateItem(T item)
    {
        item = this.getDao().merge(item);
        this.getDao().save(item);
    }

    public void saveItem(T item)
    {
        this.getDao().save(item);
    }

}
